import { BodySetup } from "utils/creep/CreepSetup";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";
import { priority } from "utils/constants/definetypes";
import { role_crossLevel } from "utils/constants/moveConstant";
import { CreepAbilityHelper } from "utils/creep/CreepAbilityHelper";

/**
 * 升级Action
 */
export class ActionTeamCombatMove  extends ActionBase<IActionCMD<"combatMove">>
{
    public execute(action: IActionCMD<"combatMove">): ActionCode 
    {
        const entity = action.arg.entity;
        const movetarget =  entity.moveTarget();
        if( movetarget)
        {
            const anchor = entity.center();
            const p_target = movetarget.pos;
            const targetVec:IFVector2={x:p_target.x-anchor.x,y:p_target.y-anchor.y};
            //if(!targetVec.x  && !targetVec.y )
            {
                // global.Log.Info(`${JSON.stringify(anchor)} ---> ${JSON.stringify(p_target)}`);
            }
            {
                const heal = _.sum(entity.aroundHostileCreeps,(e=>CreepAbilityHelper.getCreepHealAbility( e)));
                if(heal>100)
                {
                    if(entity.moveFlee(targetVec))
                    {
                        entity.log("info",`跑路:`);
                        return 0
                    }
                    if(entity.standard(targetVec))
                    {
                        entity.log("info",`原地:`);
                        return 0
                    }
                    if(entity.moveClose(targetVec))
                    {
                        entity.log("info",`进攻:`);
                        return 0
                    }
                    entity.log("info",`没有指令:`);
                }
                else
                {
                    if(entity.moveClose(targetVec,true))
                    {
                        entity.log("info",`直接进攻:`);
                        return 0
                    }
                }
                
                entity.registerCurrentBlock();  // 没有移动指令就阻挡当前的位置
            }
        }
        return 0;
    }
}